let MS = require("./ms.js")
const request = require("./request.js")
const Error = require('./error')
const storage = require("./storage.js")
const {
    isObject,
    isString,
    isNumber,
    isUndefined,
    isArray
} = require('./dataType')

const explore = class explore {

    constructor() {

    }

    query(options) {
        let params = {
            pageNum: 1,
            pageSize: 10
        }
        if(!isUndefined(options) && isObject(options)) {
            if(!isUndefined(options.pageNum) && isNumber(options.pageNum)) {
                params.pageNum = options.pageNum;
            }
            if(!isUndefined(options.pageSize) && isNumber(options.pageSize)) {
                params.pageSize = options.pageSize;
            }
        }
        return new Promise((resolve, reject) => {
            request(MS._config.parameters.EXPLORE.LOAD_EXPLORE.url,
                MS._config.parameters.EXPLORE.LOAD_EXPLORE.method, params).then(res => {
                resolve(res.data)
            }).catch(err => {
                reject(err)
            })
        })
    }

    get(id) {
        let params = {id: id}
        return new Promise((resolve, reject) => {
            request(MS._config.parameters.EXPLORE.GET_DETAIL.url,
                MS._config.parameters.EXPLORE.GET_DETAIL.method, params).then(res => {
                resolve(res.data)
            }).catch(err => {
                reject(err)
            })
        })
    }

    findExploreGoods(exploreId) {
        let params = {
            exploreId: exploreId
        }
        return new Promise((resolve, reject) => {
            request(MS._config.parameters.EXPLORE.FIND_EXPLORE_GOODS.url,
                MS._config.parameters.EXPLORE.FIND_EXPLORE_GOODS.method, params).then(res => {
                resolve(res.data)
            }).catch(err => {
                reject(err)
            })
        })
    }
}

module.exports = explore